;
layui.define(["table", "form"],
function(e) {
    var $ = layui.$,
    i = (layui.$, layui.admin),
    t = layui.view,
    l = layui.table,
    r = layui.form;
    var member_id = 0;
    if(layui.params && layui.params.id){
        member_id = layui.params.id;
        layui.params = {};
    }
    l.render({
        elem: "#LAY-sale-manage",
        url: layui.setter.baseUrl+"sale/index"+(member_id?'?member_id='+member_id:''),
        cols: [[{
            field: "id",
            title: "编号ID"
        },
        {
            field: "member_id",
            title: "商户编号"
        },
        {
            field: "title",
            title: "活动标题"
        },
        {
            field: "paytype",
            title: "活动类型",
            templet: '#paytypeTpl'
        },
        {
            field: "view",
            title: "已扫次数"
        },
        {
            field: "number",
            title: "扫码次数"
        },
        {
            field: "status",
            title: "活动状态",
            templet: '#statusTpl'
        },
        {
            field: "createtime",
            title: "创建时间"
        },
        {
            title: "操作",
            width: 430,
            align: "center",
            fixed: "right",
            style: "overflow: auto",
            toolbar: "#table-sale-oper"
        }]],
        page: !0,
        limit: 10,
        text: {
            none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
        }
    }),
    l.on("tool(LAY-sale-manage)",
    function(e) {
        var l = e.data;
        if("del" === e.event){
            layer.confirm("确定删除吗？",function(i) {
                $.post(
                    layui.setter.baseUrl+'sale/del',
                    {id: l.id},
                    function(ret){
                        var {code,msg,data} = ret;
                        layer.alert(msg);
                        if(code==0){
                            layui.table.reload('LAY-sale-manage');
                        }
                    }
                );
            })
        }
        if("edit" === e.event){
            i.popup({
                title: "编辑活动",
                area: [$(window).width()*0.618+'px', $(window).height()*0.9+'px'],
                id: "LAY-popup-sale-edit",
                success: function(e, i) {
                    t(this.id).render("sale/edit", l);
                }
            })
        }
        if("copy" === e.event){
            i.popup({
                title: "添加活动",
                area: [$(window).width()*0.618+'px', $(window).height()*0.9+'px'],
                id: "LAY-popup-sale-copy",
                success: function(e, i) {
                    var date = new Date(l.endtime * 1000);
                    var dt = date.getFullYear() + '-';
                    dt += (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    dt += (Array(2).join(0) + date.getDate()).slice(-2) + ' ';
                    l.endtime = dt;
                    t(this.id).render("sale/copy", l);
                }
            })
        }
        if("paytype0" === e.event){
            i.popup({
                title: "核销员",
                area: [$(window).width()*0.618+'px', $(window).height()*0.9+'px'],
                id: "LAY-popup-sale-verifyer",
                success: function(e, i) {
                    layui.params = l;
                    t(this.id).render("sale/verifyer", l);
                }
            })
        }
        if("tuiguang" === e.event){
            i.popup({
                title: "推广",
                area: [$(window).width()*0.618+'px', $(window).height()*0.9+'px'],
                id: "LAY-popup-sale-tuiguang",
                success: function(e, i) {
                    layui.params = l;
                    t(this.id).render("sale/tuiguang", l);
                }
            })
        }
        if("lqjl" === e.event){
            i.popup({
                title: "领券记录",
                area: [$(window).width()*0.618+'px', $(window).height()*0.9+'px'],
                id: "LAY-popup-sale-cards",
                success: function(e, i) {
                    layui.params = l;
                    t(this.id).render("sale/cards", l);
                }
            })
        }
        if("cyyh" === e.event){
            i.popup({
                title: "参与用户",
                area: [$(window).width()*0.618+'px', $(window).height()*0.9+'px'],
                id: "LAY-popup-sale-users",
                success: function(e, i) {
                    layui.params = l;
                    t(this.id).render("sale/users", l);
                }
            })
        }
        if("hdsj" === e.event){
            i.popup({
                title: "活动数据",
                area: ['900px', '370px'],
                id: "LAY-popup-sale-datas",
                success: function(e, i) {
                    layui.params = l;
                    t(this.id).render("sale/datas", l);
                }
            })
        }
        if("cjspjl" === e.event){
            i.popup({
                title: "合成视频记录",
                area: ['900px', '370px'],
                id: "LAY-popup-create_video-index",
                success: function(e, i) {
                    layui.params = l;
                    t(this.id).render("create_video/index", l);
                }
            })
        }
        if("sclb" === e.event){
            i.popup({
                title: "视频素材",
                area: ['900px', '370px'],
                id: "LAY-popup-material-index",
                success: function(e, i) {
                    layui.params = l;
                    t(this.id).render("material/index", l);
                }
            })
        }
        if("more" === e.event){
            layui.morehover = true;
            layui.params = l;
            $('.btnbox').css({
                'top': $(this).offset().top-26+'px',
                'right': $(this).offset().right+'px'
            }).fadeIn(100);
            
            $(this).mouseleave(function(){
                layui.morehover = false;
                setTimeout(function(){
                    if(!layui.morehover){
                        $('.btnbox').fadeOut(100);
                    }
                },300);
            });
        }
    }),
    e("sale", {})
});